import { ref } from 'vue'
import _ from 'lodash-es'
import Api from '@/libs/api'
import { useI18n } from 'vue-i18n'

export const useGoodsKeywords = () => {
	const { t } = useI18n()
	const isKeyWordAdding = ref(false)

	const addKeyword = (e: Event, keywords: string[]) => {
		const value = (e.target as HTMLInputElement).value
		if (value) {
			const keyword = value
			if (_.includes(keywords, keyword)) {
				Api.notify(t('商品详细.关键字已存在'))
			} else {
				keywords.push(keyword)
			}
		}
		isKeyWordAdding.value = false
	}

	return {
		isKeyWordAdding,
		addKeyword
	}
}
